package com.morphiastic.tests.fieldbridges;

import org.junit.Test;

import com.mongodb.Mongo;
import com.morphiastic.ElasticStore;
import com.morphiastic.ElasticStoreOptions;
import com.morphiastic.Morphiastic;
import com.morphiastic.MorphiasticDataStore;
import com.morphiastic.tests.utils.RandomTextGen;

public class FieldBridgesTest1 {
	Mongo mongo;
	Morphiastic morphia;
	MorphiasticDataStore ds;
	ElasticStore es;
	
	GeonameDAO  geonameDAO;
	
	String dbname = "fieldbridgestest";
	String indexName = "fieldbridgestest";
	
	@Test
	public void doTest() throws Exception{
		
		try {
			
		
		prepare();
		initializeDAOs();
		
		generate();
		
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	
	private void prepare() throws Exception{
		
		this.mongo = new Mongo("localhost:27017");
		ElasticStoreOptions opts = new ElasticStoreOptions();
		opts.setForceIndexReCreation(true);
		this.es = new ElasticStore(dbname, null, opts);
		morphia = new Morphiastic();
		this.ds = morphia.createDataStore(mongo, dbname, es);
		
	}
	
	
	
	
	private void initializeDAOs(){
		System.out.println();
			System.out.println("***************************************************************************************");
			System.out.println("***************************************************************************************");
			System.out.println("***************************************************************************************");
			
			geonameDAO = new GeonameDAOMorph(Geoname.class, ds);
	}
	
	
	
	
	private void generate() throws Exception{
		
		for (int i = 0; i < 10; i++) {
			Geoname g = new Geoname((long) i, RandomTextGen.getRandomWord(), "AIRP");
			geonameDAO.index(g);
		}
		
	}
	
	
	
}
